package com.db.nio;

import java.io.*;
import java.nio.channels.FileChannel;

public class FileCopyNIO extends AbstractCopy {
    public static void main(String[] args) {
        System.out.println("started");

        long startTime = System.currentTimeMillis();

        try (FileChannel inputChannel = new FileInputStream(FILE_1).getChannel();
             FileChannel outputChannel = new FileOutputStream(FILE_2).getChannel()) {

            inputChannel.transferTo(0, inputChannel.size(), outputChannel);

            long time = System.currentTimeMillis() - startTime;

            System.out.println("success");
            System.out.println(time + "ms");

        } catch (IOException e) {
            System.out.println("input output exception");
        }
    }
}
